package view.item
{
	import flash.display.Shape;
	import flash.display.Sprite;
	
	import ghostcat.util.easing.TweenUtil;

	/**
	 * 角色生命条 
	 * @author leo
	 * 
	 */	
	public class RoleLife extends Sprite
	{
		/**
		 * 黑色底层 
		 */		
		private var bottom :Shape;
		/**
		 * 红色顶层 
		 */		
		private var top :Shape;
		private var animationObj :AnimationObj;
		public function RoleLife(animationObj :AnimationObj)
		{
			super();
			this.animationObj = animationObj;
			this.bottom = new Shape();
			this.top = new Shape();
			
			draw(this.bottom,0);
			this.addChild(this.bottom);
			
			draw(this.top,0xff0000);
			this.addChild(this.top);
		}
		/**
		 * 设置血条 
		 * @param value
		 * 
		 */		
		public function setLife(value :Number,hp :int):void
		{
			if(this.top.width <= 0)
			{
				return;
			}
//			TweenUtil.to(this.top,1000,{width:(this.top.width - value)});
			var sub :Number = (this.bottom.width/hp * value);
			this.top.width = this.top.width - value;
		}
		
		private function draw(shape :Shape,color :uint):Shape
		{
			shape.graphics.beginFill(color);
			shape.graphics.drawRect(0,0,animationObj.width,5);
			shape.graphics.endFill();
			shape.x = -animationObj.width/2 - Math.abs(shape.width - animationObj.width)/2;
			shape.y = -animationObj.height + 15;
			return shape;
		}
		
	}
}